<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\card\model;

class CardJob extends \app\BaseModel
{
    protected $name = "longbing_card_job";
    protected static function init()
    {
    }
    public function getListByUser($card_id = 0, $uniacid)
    {
        $list = self::where([["uniacid", "=", $uniacid], ["status", "=", 1]])->field(["id", "name"])->order("top", "desc")->select()->toArray();
        if(!$list) {
            $list = $this->initCardJob($uniacid);
        }
        foreach ($list as $index => $item) {
            $list[$index]["selected"] = 0;
            if(isset($item["id"]) && $item["id"] == $card_id) {
                $list[$index]["selected"] = 1;
            }
        }
        return $list;
    }
    public function initCardJob($uniacid)
    {
        $data = [["name" => "首席服务官", "uniacid" => $uniacid]];
        $result = self::createRows($data);
        return $result->toArray();
    }
    public function createJob($data)
    {
        $data["create_time"] = time();
        $result = $this->save($data);
        return !empty($result);
    }
    public function updateJob($filter, $data)
    {
        $data["update_time"] = time();
        $result = $this->where($filter)->update($data);
        return !empty($result);
    }
    public function listJob($filter, $page_config = ["page" => 1, "page_count" => 20])
    {
        $result = $this->where($filter)->order("top desc , id desc")->page($page_config["page"], $page_config["page_count"])->select();
        if(!empty($result)) {
            $result = $result->toArray();
        }
        return $result;
    }
    public function getJob($filter)
    {
        $result = $this->where($filter)->find();
        if(!empty($result)) {
            $result = $result->toArray();
        }
        return $result;
    }
    public function delJob($filter)
    {
        $result = $this->updateJob($filter, ["status" => -1, "update_time" => time()]);
        return !empty($result);
    }
    public function getJobCount($filter)
    {
        $result = $this->where($filter)->count();
        return $result;
    }
}

?>